REGISTER /home/geil/pig/kmgross/piggybank-0.12.0.jar;
DEFINE UnixToISO         org.apache.pig.piggybank.evaluation.datetime.convert.UnixToISO();
rawdata = load 'cql://kmexample/rawdata2'
          using CqlStorage() as
           (firstname:tuple(name:chararray,value:chararray),
            surname:tuple(name:chararray,value:chararray),
            date:tuple(name:chararray,value:long),
            fromcity:tuple(name:chararray,value:chararray),
            km:tuple(name:chararray,value:long),
            tocity:tuple(name:chararray,value:chararray)
           );
flat = foreach rawdata generate
       SUBSTRING(UnixToISO(date.value),0,4) as year,
       SUBSTRING(UnixToISO(date.value),5,7) as month,
       km.value as km;
grp = group flat by (year, month);
agg = foreach grp generate group.year as year, group.month as month, SUM(flat.km) as km;
STORE agg INTO 'cfs:///$outpath' USING PigStorage (';');